#!/usr/bin/perl -w 
use DBI;

$db_login='root';
$db_password='!@#Xp!1776';
$db_host='127.0.0.1';
$db_database='peq';

# Initial connection to the database. Leave this open or close it between each transaction ?

  

sub EVENT_SPAWN
{

}

sub EVENT_SAY
{
  if($text=~/Hail/i) {
    $dbh=DBI->connect('DBI:mysql:' . $db_database . ';host=' . $db_host, $db_login, $db_password) || die "Could not connect to database: $DBI::errstr";
    $sth = $dbh->prepare('SELECT item_id FROM bazaar WHERE charid=' . $charid);
    $sth->execute();
    while (@row=$sth->fetchrow_array){
      $sth1 = $dbh->prepare('SELECT name FROM items WHERE id=' . $row[0]);
      $sth1->execute();
        while (@rows=$sth1->fetchrow_array){
          quest::shout($rows[0]);
        }
    }
  }
}

sub EVENT_ITEM
{
  plugin::check_handin(\%itemcount);
    
  # LOOP THROUGH IT
  while (($item, $count) = each(%itemcount)){
    if ($item!=0){
      &ADD_ITEM($charid, $item, $count);
    }
  }
}

sub EVENT_TIMER
{
}

sub ADD_ITEM
{
  $dbh=DBI->connect('DBI:mysql:' . $db_database . ';host=' . $db_host, $db_login, $db_password) || die "Could not connect to database: $DBI::errstr";
  $sth = $dbh->prepare('INSERT INTO bazaar (charid, item_id, count) VALUES ('.$_[0].','.$_[1].','. $_[2].')');
  $sth->execute();
}

$dbh ->disconnect();
